

package com.hazelcast.map.impl;

import com.hazelcast.map.listener.MapListener;

import static com.hazelcast.map.impl.MapListenerAdaptors.createMapListenerAdaptor;

/**
 * Contains support methods for creating various {@link com.hazelcast.map.impl.ListenerAdapter ListenerAdapter}
 *
 * @see com.hazelcast.map.impl.MapListenerAdaptors
 */
public final class ListenerAdapters {

    private ListenerAdapters() {
    }

    public static <T> ListenerAdapter<T> createListenerAdapter(Object listener) {
        if (listener instanceof ListenerAdapter) {
            return ((ListenerAdapter<T>) listener);
        }

        if (listener instanceof MapListener mapListener) {
            return createMapListenerAdaptor(mapListener);
        }

        throw new IllegalArgumentException("Not a valid type to create a listener: " + listener.getClass().getSimpleName());
    }
}
